#include "Shapes.h"

void Shapes::setCube(Ogre::Entity* pshapes, Ogre::SceneNode* pshapeNode, Ogre::AxisAlignedBox pshapeBox, int pIndices)
{
		shapes = mSceneMgr->createEntity(Ogre::StringConverter::toString(pshapes)+Ogre::StringConverter::toString(pIndices), "HideAndSeekBox.mesh");
		shapes->setMaterialName("HideAndSeek/Cube");
		shapeBox = shapes->getBoundingBox();
		shapeNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Cube"+Ogre::StringConverter::toString(pIndices)+"Node", cubeOffset[pIndices]);
		shapeNode->showBoundingBox(false);
		shapes->setVisible(true);
		shapeNode->attachObject(shapes);

		pshapes = shapes;
		pshapeNode = shapeNode;
		pshapeBox = shapeBox;
}

void Shapes::setSphere(Ogre::Entity* pshapes, Ogre::SceneNode* pshapeNode, Ogre::AxisAlignedBox pshapeBox, int pIndices)
{
		int i = 0;
		shapes = mSceneMgr->createEntity(Ogre::StringConverter::toString(pshapes)+Ogre::StringConverter::toString(pIndices), "HideAndSeekSphere.mesh");
		shapes->setMaterialName("HideAndSeek/Sphere");
		shapeBox = shapes->getBoundingBox();
		shapeNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Sphere"+Ogre::StringConverter::toString(pIndices)+"Node", sphereOffset[pIndices]);
		shapeNode->showBoundingBox(false);
		shapes->setVisible(true);
		shapeNode->attachObject(shapes);

		pshapes = shapes;
		pshapeNode = shapeNode;
		pshapeBox = shapeBox;
		
}

void Shapes::setTetra(Ogre::Entity* pshapes, Ogre::SceneNode* pshapeNode, Ogre::AxisAlignedBox pshapeBox, int pIndices)
{
		int i = 0;
		shapes = mSceneMgr->createEntity(Ogre::StringConverter::toString(pshapes)+Ogre::StringConverter::toString(pIndices), "HideAndSeekTetra.mesh");
		shapes->setMaterialName("HideAndSeek/Tetra");
		shapeBox = shapes->getBoundingBox();
		shapeNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Tetra"+Ogre::StringConverter::toString(pIndices)+"Node", tetraOffset[pIndices]);
		shapeNode->showBoundingBox(false);
		shapes->setVisible(true);
		shapeNode->attachObject(shapes);

		pshapes = shapes;
		pshapeNode = shapeNode;
		pshapeBox = shapeBox;
	
}

void Shapes::setTube(Ogre::Entity* pshapes, Ogre::SceneNode* pshapeNode, Ogre::AxisAlignedBox pshapeBox, int pIndices)
{
		shapes = mSceneMgr->createEntity(Ogre::StringConverter::toString(pshapes)+Ogre::StringConverter::toString(pIndices), "HideAndSeekTube.mesh");
		shapes->setMaterialName("HideAndSeek/Tube");
		shapeBox = shapes->getBoundingBox();
		shapeNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Tube"+Ogre::StringConverter::toString(pIndices)+"Node", tubeOffset[pIndices]);
		shapeNode->showBoundingBox(false);
		shapes->setVisible(true);
		shapeNode->attachObject(shapes);

		pshapes = shapes;
		pshapeNode = shapeNode;
		pshapeBox = shapeBox;

}

void Shapes::setPosition(Ogre::Entity* pshapes, Ogre::SceneNode* pshapeNode)
{
	bool visible = false;

	do
	{
		if(pshapes->getVisible() == false)
		{
			pshapes->setVisible(true);
			visible = true;

			if(visible = true)
				pshapeNode->showBoundingBox(true);
		}
	} while(visible == false);
}

void Shapes::createScene(void)
{
	srand((unsigned)time(NULL));

	this->cube[NUMSHAPES] = new Shapes();
	this->sphere[NUMSHAPES] = new Shapes();
	this->tetra[NUMSHAPES] = new Shapes();
	this->tube[NUMSHAPES] = new Shapes();
	for(int i = 0; i< NUMSHAPES; i++)
	{
		cube[i]->setCube(Shapes::shapes, Shapes::shapeNode, Shapes::shapeBox, i);
		sphere[i]->setCube(Shapes::shapes, Shapes::shapeNode, Shapes::shapeBox, i);
		tetra[i]->setCube(Shapes::shapes, Shapes::shapeNode, Shapes::shapeBox, i);
		tube[i]->setCube(Shapes::shapes, Shapes::shapeNode, Shapes::shapeBox, i);
	}

	int rndInt = (rand() % NUMSHAPES) + 1;
	for(int i = 0; i < rndInt; i++)
	{
		int rndPos = rand() % NUMSHAPES;
		cube[rndPos]->setPosition(Shapes::shapes, Shapes::shapeNode);
	}

	rndInt = (rand() % NUMSHAPES) + 1;
	for(int i = 0; i < rndInt; i++)
	{
		int rndPos = rand() % NUMSHAPES;
		sphere[rndPos]->setPosition(Shapes::shapes, Shapes::shapeNode);
	}

	rndInt = (rand() % NUMSHAPES) + 1;
	for(int i = 0; i < rndInt; i++)
	{
		int rndPos = rand() % NUMSHAPES;
		tetra[rndPos]->setPosition(Shapes::shapes, Shapes::shapeNode);
	}

	rndInt = (rand() % NUMSHAPES) + 1;
	for(int i = 0; i < rndInt; i++)
	{
		int rndPos = rand() % NUMSHAPES;
		tube[rndPos]->setPosition(Shapes::shapes, Shapes::shapeNode);
	}
}


/*

#pragma region Shapes
/*
*	All the shapes are confined to the following boundaries:
*	X: +180 to -180
*	Y: 0 to -300
*	Z: +180 to -180
*/
/*
	srand((unsigned)time(NULL));
	hiddenInt = rand() % NUMPLANES;

#pragma region Offsets
/*
*  Cubes

	Ogre::Vector3 cubeOffset[9];
	cubeOffset[0] = Ogre::Vector3(70.0f,	cubeBox[0].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y,	10.0f);
	cubeOffset[1] = Ogre::Vector3(10.0f,	cubeBox[1].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y, 100.0f);
	cubeOffset[2] = Ogre::Vector3(-180.0f,	cubeBox[2].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y, 180.0f);
	cubeOffset[3] = Ogre::Vector3(180.0f,	cubeBox[3].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y, 180.0f);
	cubeOffset[4] = Ogre::Vector3(-97.0f,	cubeBox[4].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y, -102.0f);
	cubeOffset[5] = Ogre::Vector3(130.0f,	cubeBox[5].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y, -53.0f);
	cubeOffset[6] = Ogre::Vector3(152.0f,	cubeBox[6].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y, -173.0f);
	cubeOffset[7] = Ogre::Vector3(146.0f,	cubeBox[7].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y, 20.0f);
	cubeOffset[8] = Ogre::Vector3(35.0f,	cubeBox[8].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y, -100.0f);
/*
*  Spheres

	Ogre::Vector3 sphereOffset[9];
	sphereOffset[0] = Ogre::Vector3(10.0f,	sphereBox[0].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -100.0f, 10.0f);
	sphereOffset[1] = Ogre::Vector3(73.0f,	sphereBox[1].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -100.0f, -161.0f);
	sphereOffset[2] = Ogre::Vector3(13.0f,	sphereBox[2].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -100.0f, -147.0f);
	sphereOffset[3] = Ogre::Vector3(-121.0f,sphereBox[3].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -100.0f, 36.0f);
	sphereOffset[4] = Ogre::Vector3(-150.0f,sphereBox[4].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -100.0f, -122.0f);
	sphereOffset[5] = Ogre::Vector3(-173.0f,sphereBox[5].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -100.0f, 1.0f);
	sphereOffset[6] = Ogre::Vector3(69.0f,	sphereBox[6].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -100.0f, 69.0f);
	sphereOffset[7] = Ogre::Vector3(173.0f,	sphereBox[7].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -100.0f, 15.0f);
	sphereOffset[8] = Ogre::Vector3(29.0f,	sphereBox[8].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -100.0f, 180.0f);
/*
*  Tetra

	Ogre::Vector3 tetraOffset[9];
	tetraOffset[0] = Ogre::Vector3(10.0f,	tetraBox[0].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -200.0f, 10.0f);
	tetraOffset[1] = Ogre::Vector3(32.0f,	tetraBox[1].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -200.0f, -159.0f);
	tetraOffset[2] = Ogre::Vector3(169.0f,	tetraBox[2].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -200.0f, -25.0f);
	tetraOffset[3] = Ogre::Vector3(111.0f,	tetraBox[3].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -200.0f, 159.0f);
	tetraOffset[4] = Ogre::Vector3(-100.0f, tetraBox[4].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -200.0f, 9.0f);
	tetraOffset[5] = Ogre::Vector3(-177.0f, tetraBox[5].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -200.0f, 177.0f);
	tetraOffset[6] = Ogre::Vector3(-150.0f, tetraBox[6].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -200.0f, -68.0f);
	tetraOffset[7] = Ogre::Vector3(-40.0f,	tetraBox[7].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -200.0f, 125.0f);
	tetraOffset[8] = Ogre::Vector3(88.0f,	tetraBox[8].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -200.0f, 60.0f);
/*
*  Tube


	Ogre::Vector3 tubeOffset[9];
	tubeOffset[0] = Ogre::Vector3(10.0f,	tubeBox[0].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -300.0f, 10.0f);
	tubeOffset[1] = Ogre::Vector3(-101.0f,	tubeBox[1].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -300.0f, 162.0f);
	tubeOffset[2] = Ogre::Vector3(40.0f,	tubeBox[2].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -300.0f, 154.0f);
	tubeOffset[3] = Ogre::Vector3(-30.0f,	tubeBox[3].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -300.0f, 99.0f);
	tubeOffset[4] = Ogre::Vector3(127.0f,	tubeBox[4].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -300.0f, 44.0f);
	tubeOffset[5] = Ogre::Vector3(136.0f,	tubeBox[5].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -300.0f, -121.0f);
	tubeOffset[6] = Ogre::Vector3(-149.0f,	tubeBox[6].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -300.0f, -139.0f);
	tubeOffset[7] = Ogre::Vector3(-15.0f,	tubeBox[7].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -300.0f, -166.0f);
	tubeOffset[8] = Ogre::Vector3(180.0f,	tubeBox[8].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -300.0f, -170.0f);

/*
*  Hidden Shape

	Ogre::Vector3 hiddenOffset[4];
	hiddenOffset[0]	= Ogre::Vector3(rand() % 180, hiddenBox[0].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y, rand() % 180);
	hiddenOffset[1]	= Ogre::Vector3(rand() % 180, hiddenBox[1].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -100.0f, rand() % 180);
	hiddenOffset[2]	= Ogre::Vector3(rand() % 180, hiddenBox[2].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y + -200.0f, rand() % 180);
	hiddenOffset[3]	= Ogre::Vector3(rand() % 180, hiddenBox[3].getCorner(Ogre::AxisAlignedBox::FAR_LEFT_BOTTOM).y +- 300.0f, rand() % 180);

#pragma endregion Offsets
//-------------------------------------------------------------------------------------
#pragma region SwitchHiddenShape

	switch(hiddenInt)
	{
	case 0:
		hiddenShape = mSceneMgr->createEntity("HiddenShape"+Ogre::StringConverter::toString(1), "HideAndSeekBox.mesh");
		hiddenShape->setMaterialName("HideAndSeek/Cube");
		hiddenBox = hiddenShape->getBoundingBox();
		hiddenNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("HiddenNode"+Ogre::StringConverter::toString(1), hiddenOffset[0]);
		hiddenNode->showBoundingBox(false);
		hiddenShape->setVisible(true);
		hiddenNode->attachObject(hiddenShape);
		break;
	case 1:
		hiddenShape = mSceneMgr->createEntity("HiddenShape"+Ogre::StringConverter::toString(2), "HideAndSeekSphere.mesh");
		hiddenShape->setMaterialName("HideAndSeek/Sphere");
		hiddenBox = hiddenShape->getBoundingBox();
		hiddenNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("HiddenNode"+Ogre::StringConverter::toString(2), hiddenOffset[1]);
		hiddenNode->showBoundingBox(false);
		hiddenShape->setVisible(true);
		hiddenNode->attachObject(hiddenShape);
		break;
	case 2:
		hiddenShape = mSceneMgr->createEntity("HiddenShape"+Ogre::StringConverter::toString(3), "HideAndSeekTetra.mesh");
		hiddenShape->setMaterialName("HideAndSeek/Tetra");
		hiddenBox = hiddenShape->getBoundingBox();
		hiddenNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("HiddenNode"+Ogre::StringConverter::toString(3), hiddenOffset[2]);
		hiddenNode->showBoundingBox(false);
		hiddenShape->setVisible(true);
		hiddenNode->attachObject(hiddenShape);
		break;
	case 3:
		hiddenShape = mSceneMgr->createEntity("HiddenShape"+Ogre::StringConverter::toString(4), "HideAndSeekTube.mesh");
		hiddenShape->setMaterialName("HideAndSeek/Barrel");
		hiddenBox = hiddenShape->getBoundingBox();
		hiddenNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("HiddenNode"+Ogre::StringConverter::toString(4), hiddenOffset[3]);
		hiddenNode->showBoundingBox(false);
		hiddenShape->setVisible(true);
		hiddenNode->attachObject(hiddenShape);
		break;
	}

#pragma endregion SwitchHiddenShape
//-------------------------------------------------------------------------------------
#pragma region Planes


	int i = 0;
	for(int j = 0.0f; i < NUMPLANES; j-= 100.0f)
	{
		planes[i] = mSceneMgr->createEntity("Plane" + Ogre::StringConverter::toString(i+1), "HideAndSeekPlane.mesh");
		planes[i]->setMaterialName("HideAndSeek/Glass");

		Ogre::AxisAlignedBox planeBox = planes[i]->getBoundingBox();	// Get the AABB of the planes

		/*
		*	Sets the object's and the AABB position to each PlaneNode
		
		planeNode[i] =
		mSceneMgr->getRootSceneNode()->createChildSceneNode("Plane" + Ogre::StringConverter::toString(i+1) + "Node",
															Ogre::Vector3(0.0f, -planeBox.getCorner(Ogre::AxisAlignedBox::FAR_LEFT_TOP).y + j, 0.0f));
		
		planeNode[i]->showBoundingBox(true);	// Show the AABB's

		planeNode[i]->attachObject(planes[i]);
		
		i++;
	}

#pragma endregion Planes
//-------------------------------------------------------------------------------------
#pragma region Cubes

	for(int i = 0; i < NUMSHAPES; i++)
	{
		cubes[i] = mSceneMgr->createEntity("Cube"+Ogre::StringConverter::toString(i+1), "HideAndSeekBox.mesh");
		cubes[i]->setMaterialName("HideAndSeek/Cube");
		cubeBox[i] = cubes[i]->getBoundingBox();
		cubeNodes[i] = mSceneMgr->getRootSceneNode()->createChildSceneNode("Cube"+Ogre::StringConverter::toString(i+1)+"Node", cubeOffset[i]);
		cubeNodes[i]->showBoundingBox(false);
		cubes[i]->setVisible(false);
		cubeNodes[i]->attachObject(cubes[i]);
	}

	int rndInt = (rand() % NUMSHAPES) + 1;
	for(int i = 0; i < rndInt; i++)
	{
		bool visible = false;
		do
		{
			int rndPos = rand() % NUMSHAPES;

			if (cubes[rndPos]->getVisible() == false)
			{
				cubes[rndPos]->setVisible(true);
				visible = true;

				if(visible = true)
					cubeNodes[rndPos]->showBoundingBox(true);
			}
		} while (visible == false);
	}

	

	// Get number of total shapes so far
	totalShapes = rndInt;

#pragma endregion Cubes
//-------------------------------------------------------------------------------------
#pragma region Spheres

	for(int i = 0; i < NUMSHAPES; i++)
	{
		spheres[i] = mSceneMgr->createEntity("Sphere"+Ogre::StringConverter::toString(i+1), "HideAndSeekSphere.mesh");
		spheres[i]->setMaterialName("HideAndSeek/Sphere");
		sphereBox[i] = spheres[i]->getBoundingBox();
		sphereNodes[i] = mSceneMgr->getRootSceneNode()->createChildSceneNode("Sphere"+Ogre::StringConverter::toString(i+1)+"Node", sphereOffset[i]);
		sphereNodes[i]->attachObject(spheres[i]);
		spheres[i]->setVisible(false);
	}

	rndInt = (rand() % NUMSHAPES) + 1;
	for(int i = 0; i < rndInt; i++)
	{
		bool visible = false;
		do
		{
			int rndPos = rand() % NUMSHAPES;

			if (spheres[rndPos]->getVisible() == false)
			{
				spheres[rndPos]->setVisible(true);
				visible = true;

				if(visible = true)
					sphereNodes[rndPos]->showBoundingBox(true);
			}
		} while (visible == false);
	}
	
	// Get number of total shapes so far
	totalShapes += rndInt;

#pragma endregion Spheres
//-------------------------------------------------------------------------------------
#pragma region Tetra

	for(int i = 0; i < NUMSHAPES; i++)
	{
		tetrahedrons[i] = mSceneMgr->createEntity("Tetrahedron"+Ogre::StringConverter::toString(i+1), "HideAndSeekTetra.mesh");
		tetrahedrons[i]->setMaterialName("HideAndSeek/Tetra");
		tetraBox[i] = tetrahedrons[i]->getBoundingBox();
		tetraNodes[i] = mSceneMgr->getRootSceneNode()->createChildSceneNode("Tetra"+Ogre::StringConverter::toString(i+1)+"Node", tetraOffset[i]);
		tetraNodes[i]->showBoundingBox(false);
		tetrahedrons[i]->setVisible(false);
		tetraNodes[i]->attachObject(tetrahedrons[i]);
	}
	
	rndInt = (rand() % NUMSHAPES) + 1;
	for(int i = 0; i < rndInt; i++)
	{
		bool visible = false;
		do
		{
			int rndPos = rand() % NUMSHAPES;

			if(tetrahedrons[rndPos]->getVisible() == false)
			{
				tetrahedrons[rndPos]->setVisible(true);
				visible = true;

				if(visible = true)
					tetraNodes[rndPos]->showBoundingBox(true);
			}
		} while (visible == false);
	}

	// Get number of total shapes so far
	totalShapes += rndInt;

#pragma endregion Tetra
//-------------------------------------------------------------------------------------
#pragma region Cylinder

	for(int i = 0; i < NUMSHAPES; i++)
	{
		tubes[i] = mSceneMgr->createEntity("Tube"+Ogre::StringConverter::toString(i+1), "HideAndSeekTube.mesh");
		tubes[i]->setMaterialName("HideAndSeek/Barrel");
		tubeBox[i] = tubes[i]->getBoundingBox();
		tubeNodes[i] = mSceneMgr->getRootSceneNode()->createChildSceneNode("Tube"+Ogre::StringConverter::toString(i+1), tubeOffset[i]);
		tubeNodes[i]->showBoundingBox(false);
		tubes[i]->setVisible(false);
		tubeNodes[i]->attachObject(tubes[i]);
	}

	rndInt = (rand() % NUMSHAPES) + 1;
	for(int i = 0; i < rndInt; i++)
	{
		bool visible = false;
		do
		{
			int rndPos = rand() % NUMSHAPES;

			if(tubes[rndPos]->getVisible() == false)
			{
				tubes[rndPos]->setVisible(true);
				visible = true;

				if(visible = true)
					tubeNodes[rndPos]->showBoundingBox(true);
			}
		} while (visible == false);
	}
	
	// Get number of total shapes so far
	totalShapes += rndInt;

#pragma endregion Cylinder
//-------------------------------------------------------------------------------------

#pragma endregion Shapes 
*/